package objects;

import java.io.Serializable;

public class CSProb implements Serializable{
	
	private String problem;
	private double solution;
	private Frac fSolution;
	private int[] factSolution;
	private String[] propSolution;
	private Exp expSolution;
	private String slopeInterceptForm;
	private String generalForm;
	private double yIntercept;
	private double slope;
	private double[] roots;
	public int id;
	public int lineEquId;
	
	public CSProb(String p, double s){
		problem = p;
		solution = s;
		id = 0;
	}
	
	public CSProb(String p, int n, int d){
		problem = p;
		fSolution = new Frac(n, d);
		id = 1;
	}
	
	public CSProb(String p, Exp e){
		problem = p;
		expSolution = e;
		id = 2;
	}
	
	public CSProb(String p, int[] f){
		problem = p;
		factSolution = f;
		id = 3;
	}
	
	public CSProb(String p, String[] prop){
		problem = p;
		propSolution = prop;
		id = 4;
	}
	
	public CSProb(String p, double[] r){
		problem  = p;
		roots = r;
		id = 5;
	}
	
	public CSProb(String p, String sfi, String gf, double y, double s, int i){
		problem = p;
		slopeInterceptForm = sfi;
		generalForm = gf;
		yIntercept = y;
		slope = s;
		id = 6;
		lineEquId = i;
	}
	
	public double getSolution(){
		return solution;
	}
	
	public Frac getFSolution(){
		return fSolution;
	}
	
	public int[] getFactSolution(){
		return factSolution;
	}
	
	public String[] getPropSolution(){
		return propSolution;
	}
	
	public Exp getExpSolution(){
		return expSolution;
	}
	
	public String getSlopeForm(){
		return slopeInterceptForm;
	}
	
	public String getGeneralForm(){
		return generalForm;
	}
	
	public double[] getRoots(){
		return roots;
	}
	
	public double getSlope(){
		return slope;
	}
	
	public double getYIntercept(){
		return yIntercept;
	}
	
	public String getProblem(){
		return problem;
	}
	
	public String probToJson(){
		if(id == 0){
			return "{\"currentProblem\":\""+problem+"\", \"solution\": \""+solution+"\", \"id\":\""+id+"\"}";
		}else if(id == 1){
			return "{\"currentProblem\":\""+problem+"\", \"fracSolutionNum\":\""+fSolution.num+"\", " +
					"\"fracSolutionDenom\":\""+fSolution.denom+"\", \"id\":\""+id+"\"}";
		}else if(id == 2){
			return "{\"currentProblem\":\""+problem+"\", \"expSolutionNum\":\""+expSolution.number+"\", " +
					"\"expSolutionExp\":\""+expSolution.exponent+"\", \"id\":\""+id+"\"}";
		}else if(id == 3){
			String s = "{\"currentProblem\":\""+problem+"\", \"factSolution\":[";
			for(int i=0; i<factSolution.length; i++){
				s = s +"{\"factor\":\""+factSolution[i]+"\"}";
				if(i < factSolution.length-1){
					s = s + ",";
				}
			}
			s = s + "], \"id\":\""+id+"\"}";
			System.out.println("s = "+s);
			return s;
		}else if(id == 4){
			String s = "{\"currentProblem\":\""+problem+"\", \"propSolution\":[";
			for(int i=0; i<propSolution.length; i++){
				s = s +"{\"prop\":\""+propSolution[i]+"\"}";
				if(i < propSolution.length-1){
					s = s + ",";
				}
			}
			s = s + "], \"id\":\""+id+"\"}";
			System.out.println("s = "+s);
			return s;
		}else if(id == 5){
			return "{\"currentProblem\":\""+problem+"\", \"root1\":\""+roots[0]+"\", \"root2\":\""+roots[1]+
					"\", \"id\":\""+id+"\"}";
		}else if(id == 6){
			return "{\"currentProblem\":\""+problem+"\", \"slopeIntForm\":\""+slopeInterceptForm+
					"\", \"genForm\":\""+generalForm+"\", \"yInt\":\""+yIntercept+"\", \"slope\":\""+slope+
					"\", \"lineEquId\":\""+lineEquId+"\", \"id\":\""+id+"\"}";
		}
		System.out.println("Problem type not supported");
		return null;
	}
	
}
